#[get("/view_msg?<id>&<_is_me>", rank = 2)]
fn view_msg2(id: usize, _is_me: u8, cookies: Cookies, state: State<MySqlDriver>) -> Response<'static> {
    let mut res = Response::new();
    res.set_header(ContentType::HTML);
    // let user_info: UserInfo = get_cookies(&cookies);

    // mod_id: String, 
    // mod_menu_open: String, 
    // sub_mod_id: String, 
    // page_title: String, 
    // title: String
    let header: String = get_header(
        "msg-mod".to_string(), 
        "msg-mod-menu-open".to_string(), 
        "own-msg-list".to_string(),
        "用户后台 - 查看留言".to_string(), 
        "查看留言".to_string(), &cookies,
        &state);

    let pool_result: Result<Pool, mysql::Error> = Pool::new(state.driver.as_str());
    let pool: Pool;
    if let Ok(p) = pool_result {
        pool = p;
    } else {
        res.set_sized_body(Cursor::new("无法建立数据库连接".to_string()));
        return res;
    }
    let conn_result: Result<PooledConn, mysql::Error> = pool.get_conn();
    let mut conn: PooledConn;
    if let Ok(c) = conn_result {
        conn = c;
    } else {
        res.set_sized_body(Cursor::new("无法获取数据库连接".to_string()));
        return res;
    }

    let mut sql: String = format!("UPDATE `message` SET `is_read` = 1 WHERE `id` = {}", id);
    let _ = conn.exec_drop(sql.clone(), ());

    sql = format!("SELECT `m`.`copywrite_order_id`, `m`.`clip_order_id`, `m`.`title`, `u`.`account`, `m`.`content` FROM `message` AS `m` INNER JOIN `user` AS `u` ON `u`.`id` = `m`.`sender_id` WHERE `m`.`id` = {} LIMIT 1", id);
    let row_op: Option<Row> = conn.query_first(sql.clone()).unwrap();
    let row: Row;
    if let Some(r) = row_op {
        row = r;
    } else {
        res.set_sized_body(Cursor::new("消息查询失败".to_string()));
        return res;
    }
    let (title, account, content): (String, String, String) = from_row(row);

    let mut src_vec: Vec<&[u8]> = Vec::new();
    let mut replace_vec: Vec<&[u8]> = Vec::new();

    let publish_msg: String = String::new();
    let footer_string: String = get_footer();
    src_vec.push("{header}".as_bytes());
    src_vec.push("{base_url}".as_bytes());
    src_vec.push("{account}".as_bytes());
    src_vec.push("{title}".as_bytes());
    src_vec.push("{content}".as_bytes());
    src_vec.push("{publish_msg}".as_bytes());
    src_vec.push("{footer}".as_bytes());
    replace_vec.push(header.as_bytes());
    replace_vec.push(state.base_url.as_bytes());
    replace_vec.push(account.as_bytes());
    replace_vec.push(title.as_bytes());
    replace_vec.push(content.as_bytes());
    replace_vec.push(publish_msg.as_bytes());
    replace_vec.push(footer_string.as_bytes());

    let mut page_str: HoString = HoFile::read_file_bytes("web/view_msg.html");
    page_str = page_str.replace_bytes_vec(src_vec, replace_vec);
    let html: String = page_str.to_str().to_string().to_owned();
    res.set_sized_body(Cursor::new(html));
    return res;
}

#[get("/view_msg?<id>", rank = 1)]
fn view_msg1(id: usize, cookies: Cookies, state: State<MySqlDriver>) -> Response<'static> {
    let mut res = Response::new();
    res.set_header(ContentType::HTML);
    // let user_info: UserInfo = get_cookies(&cookies);

    // mod_id: String, 
    // mod_menu_open: String, 
    // sub_mod_id: String, 
    // page_title: String, 
    // title: String
    let header: String = get_header(
        "msg-mod".to_string(), 
        "msg-mod-menu-open".to_string(), 
        "own-msg-list".to_string(),
        "用户后台 - 查看留言".to_string(), 
        "查看留言".to_string(), &cookies,
        &state);

    let pool_result: Result<Pool, mysql::Error> = Pool::new(state.driver.as_str());
    let pool: Pool;
    if let Ok(p) = pool_result {
        pool = p;
    } else {
        res.set_sized_body(Cursor::new("无法建立数据库连接".to_string()));
        return res;
    }
    let conn_result: Result<PooledConn, mysql::Error> = pool.get_conn();
    let mut conn: PooledConn;
    if let Ok(c) = conn_result {
        conn = c;
    } else {
        res.set_sized_body(Cursor::new("无法获取数据库连接".to_string()));
        return res;
    }

    let mut sql: String = format!("UPDATE `message` SET `is_read` = 1 WHERE `id` = {}", id);
    let _ = conn.exec_drop(sql.clone(), ());

    sql = format!("SELECT `m`.`sender_id` AS `receive_id`, `m`.`copywrite_order_id`, `m`.`clip_order_id`, `m`.`title`, `u`.`id` AS `uid`, `u`.`account`, `m`.`content` FROM `message` AS `m` INNER JOIN `user` AS `u` ON `u`.`id` = `m`.`sender_id` WHERE `m`.`id` = {} LIMIT 1", id);
    let row_op: Option<Row> = conn.query_first(sql.clone()).unwrap();
    let row: Row;
    if let Some(r) = row_op {
        row = r;
    } else {
        res.set_sized_body(Cursor::new("消息查询失败".to_string()));
        return res;
    }
    let (receive_id, copywrite_order_id, clip_order_id, title, uid, account, content): (usize, usize, usize, String, usize, String, String) = from_row(row);

    let mut order_type: String = String::new();
    if copywrite_order_id != 0 {
        order_type = "copywrite".to_string();
    } else if clip_order_id != 0 {
        order_type = "clip".to_string();
    }

    let mut msg_src_vec: Vec<&[u8]> = Vec::new();
    let mut msg_replace_vec: Vec<&[u8]> = Vec::new();

    let id_str: String = id.to_string();
    let receive_id_str: String = receive_id.to_string();
    let uid_str: String = uid.to_string();
    let is_me: String = "0".to_string();
    msg_src_vec.push("{id}".as_bytes());
    msg_src_vec.push("{uid}".as_bytes());
    msg_src_vec.push("{base_url}".as_bytes());
    msg_src_vec.push("{order_type}".as_bytes());
    msg_src_vec.push("{receive_id}".as_bytes());
    msg_src_vec.push("{is_me}".as_bytes());
    msg_replace_vec.push(id_str.as_bytes());
    msg_replace_vec.push(uid_str.as_bytes());
    msg_replace_vec.push(state.base_url.as_bytes());
    msg_replace_vec.push(order_type.as_bytes());
    msg_replace_vec.push(receive_id_str.as_bytes());
    msg_replace_vec.push(is_me.as_bytes());
    let mut publish_msg_html: HoString = HoFile::read_file_bytes("web/publish_msg.html");
    publish_msg_html = publish_msg_html.replace_bytes_vec(msg_src_vec, msg_replace_vec);

    let mut src_vec: Vec<&[u8]> = Vec::new();
    let mut replace_vec: Vec<&[u8]> = Vec::new();

    let footer_string: String = get_footer();
    src_vec.push("{header}".as_bytes());
    src_vec.push("{base_url}".as_bytes());
    src_vec.push("{account}".as_bytes());
    src_vec.push("{title}".as_bytes());
    src_vec.push("{content}".as_bytes());
    src_vec.push("{publish_msg}".as_bytes());
    src_vec.push("{footer}".as_bytes());
    replace_vec.push(header.as_bytes());
    replace_vec.push(state.base_url.as_bytes());
    replace_vec.push(account.as_bytes());
    replace_vec.push(title.as_bytes());
    replace_vec.push(content.as_bytes());
    replace_vec.push(publish_msg_html.to_bytes());
    replace_vec.push(footer_string.as_bytes());

    let mut page_str: HoString = HoFile::read_file_bytes("web/view_msg.html");
    page_str = page_str.replace_bytes_vec(src_vec, replace_vec);
    let html: String = page_str.to_str().to_string().to_owned();
    res.set_sized_body(Cursor::new(html));
    return res;
}

